<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal">
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <style>
      table {
      	page-break-before: auto;
      	page-break-inside: avoid;
      	page-break-after: auto;
      	margin-bottom: 1em;
      }
      tbody, thead, tr, td {
	      page-break-before: avoid;
	      page-break-after: avoid;
      }
      td, th {
  	    white-space: nowrap;
      }
      .left {
        text-align: left;
      }
      .center {
        text-align: center;
      }
      .right {
        text-align: right;
      }
    </style>
  </head>
  <body>
    <p>Tilaukset tuotteittain <span tal:replace="php:date('d.m. \k\l\o H.i')">Aikaleima</span></p>
    <tal:producers define="producers_names php:array_keys(producers);
                           sorting php:sort(producers_names)"
                   repeat="producer producers_names">
      <table>
        <thead>
          <tr>
            <th class="left" tal:content="producer">Tuottaja</th>
            <th class="left">Hinta</th>
            <th class="right">Tilaukset</th>
            <th class="right" style="padding-left:1em;">
              <span tal:replace="php:str_replace('.', ',', producers_sum[producer])">Yhteensä</span>
              &euro;
            </th>
          </tr>
        </thead>
        <tal:products define="product_names php:array_keys(producers[producer]);
                              sorting php:sort(product_names)"
                      repeat="description product_names">
          <tr tal:repeat="product php:producers[producer][description]">
            <td tal:content="description"></td>
            <td class="right">
              <span tal:replace="php:str_replace('.', ',', product['price'])"></span> &euro; /
              <span tal:replace="php:str_replace('pcs', 'kpl', product['unit'])"></span>
            </td>
            <td class="right">
              <span tal:replace="product/quantity"></span>
              <span tal:replace="php:str_replace('pcs', 'kpl', product['unit'])"></span>
            </td>
            <td style="text-align: right; padding-left:1em;"><span tal:replace="php:str_replace('.', ',', product['sum'])"></span> &euro;</td>
          </tr>
        </tal:products>
      </table>
    </tal:producers>
    <tal:other define="producers php:array('Muut' => other);
                       producers_sum php:array('Muut' => other_sum);
                       producers_names php:array_keys(producers);
                       sorting php:sort(producers_names)"
               tal:condition="php:count(other) ? true : false"
               repeat="producer producers_names">
      <table>
        <thead>
          <tr>
            <th class="left" tal:content="producer">Tuottaja</th>
            <th class="center">Hinta</th>
            <th class="right">Tilaukset</th>
            <th class="right" style="padding-left:1em;">
              <span tal:replace="php:str_replace('.', ',', producers_sum[producer])">Yhteensä</span>
              &euro;
            </th>
          </tr>
        </thead>
        <tal:products define="product_names php:array_keys(producers[producer]);
                              sorting php:sort(product_names)"
                      repeat="description product_names">
          <tr tal:repeat="product php:producers[producer][description]">
            <td tal:content="description"></td>
            <td class="center">
              <span tal:replace="php:str_replace('.', ',', product['price'])"></span> &euro; /
              <span tal:replace="php:str_replace('pcs', 'kpl', product['unit'])"></span>
            </td>
            <td class="right">
              <span tal:replace="product/quantity"></span>
              <span tal:replace="php:str_replace('pcs', 'kpl', product['unit'])"></span>
            </td>
            <td class="right" style="padding-left:1em;"><span tal:replace="php:str_replace('.', ',', product['sum'])"></span> &euro;</td>
          </tr>
        </tal:products>
      </table>
    </tal:other>
  </body>
</html>